﻿<ValueConversion(GetType(String), GetType(Boolean))>
Public Class BitConverter
    Inherits Markup.MarkupExtension
    Implements IValueConverter

    Public Sub New()
    End Sub

    Private Shared mConverter As BitConverter
    Public Overrides Function ProvideValue(serviceProvider As IServiceProvider) As Object
        If mConverter Is Nothing Then
            mConverter = New BitConverter
        End If
        Return mConverter
    End Function

    Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.Convert
        Return If(CType(value, String) = "1", True, False)
    End Function

    Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
        Return If(CType(value, Boolean), "1", "0")
    End Function

End Class
